/****************************************************************************
 *
 *  ALi (Shanghai) Corporation, All Rights Reserved. 2007 Copyright (C)
 *
 *  File: pvr_mgr_edit.c
 *
 *  Description: This file describes pvr advance edit functions.
 *
 *  History:
 *      Date        	Author      	Version  		Comment
 *      ====        	======      	=======  		=======
 *  1.  2009.3.20  		Dukula_Zhu  	0.0.1  		
 *
 ****************************************************************************/
#include "pvr_mgr_data.h"

RET_CODE 	pvr_list_rename_record(UINT16 idx, const char *name)
{
}

RET_CODE _pvr_list_copy_record(UINT16 index, const char *dest_mount_name)
{
	RET_CODE ret = RET_FAILURE;
	ppvr_mgr_list list = NULL;
	ppvr_mgr_list_item record_item = NULL;
	char src_mount_name[256];
	char dest_dir_path[1024];
	PVR_DIR *dir = NULL;
	
	list = _pvr_list_get_cur_list();
	record_item = _pvr_list_getitem_byidx(list, index);
	if( record_item == NULL )
		return ret;
	
	STRCPY(src_mount_name, "");
	STRCPY(dest_dir_path, "");
	MEMSET(dest_dir_path, 0, 1024);
	STRCPY(src_mount_name, record_item->record_dir_path);
	STRCPY(dest_dir_path, (char *)src_mount_name);
	dest_dir_path[48] = dest_dir_path[48] + 1;
	
	dir = _opendir(dest_dir_path);
	if(dir)
	{
		_closedir(dir);
		return RET_FAILURE;
	}
	pvr_fs_error(_mkdir(dest_dir_path), RET_FAILURE);
	UINT32 ptm = osal_get_tick();
			
	if(_copydir(record_item->record_dir_path, dest_dir_path) == -1)
	{
		pvr_fs_error(_emptydir(dest_dir_path), RET_FAILURE);
		pvr_fs_error(_rmdir(dest_dir_path), RET_FAILURE);
		return RET_FAILURE;
	}

	return RET_SUCCESS;
}

RET_CODE _pvr_list_copy_record_by_time(struct ListInfo rl_info, char *path, const char *dest_mount_name, UINT32 time_start, UINT32 time_end)
{
	RET_CODE ret = RET_SUCCESS;
	struct playback_param *playback;
	
	//ret = _pvr_data_copy_by_time(playback, time_start, time_end);
	if(ret == RET_FAILURE)
	{
		return ret;
	}
	_pvr_mgr_add_copy_record( rl_info,  path);
	return ret;

}

BOOL _pvr_mgr_add_copy_record(struct ListInfo rl_info, char *path)
{
	BOOL ret = TRUE;
	UINT16 index = rl_info.index;
	ppvr_mgr_list_item record_item_copy = NULL;
	ppvr_mgr_list list = NULL;
	ppvr_mgr_list_item record_item = NULL;
	
	list = _pvr_list_get_cur_list();
	record_item = _pvr_list_getitem_byidx(list, index);
	if( record_item == NULL )
		return FALSE;
	
	_pvr_mgr_malloc(record_item_copy, sizeof(pvr_mgr_list_item), 1);
	_pvr_mgr_malloc(record_item_copy->record_info, sizeof(pvr_mgr_rec_info), 1);

	record_item_copy->f_type = F_UNKOWN;
	MEMCPY( record_item_copy->record_dir_path, path, 256 );
	
	if(record_item_copy->record_info->puser_data == NULL)
		_pvr_mgr_malloc(record_item_copy->record_info->puser_data, sizeof(pvr_mgr_user_data), 1);
	record_item_copy->record_info->record = record_item->record_info->record;
	
	if( _pvr_mgr_add_record( record_item_copy, 0) == FALSE )
	{
		_pvr_mgr_free(record_item_copy->record_info->puser_data);
		_pvr_mgr_free(record_item_copy->record_info);
		_pvr_mgr_free(record_item_copy);
	}
	else
	{
		_pvr_load_record_listinfo(record_item_copy);
		MEMCPY(record_item_copy->record_info->record.txti, rl_info.txti, TXTI_LEN);
		record_item_copy->record_info->is_update = 1;
	}
	
	return ret;
}

